﻿using System;
using System.Data;

namespace Common
{
    [Serializable]
    public class ModuleData
    {

        public const string MODULE_IDField = "@module_id";

        public const string PRIMARYKEY_Field = @"module_id";

        public const string MODULE_NAMEField = "@module_name";

        public const string MODULE_DESCRField = "@module_descr";

        public const string PARENT_IDField = "@parent_id";

        public const string MODULE_URLField = "@module_url";

        public const string DIV_MODULE_CLASSField = "@div_module_class";

        public const string MODULE_CLASSField = "@module_class";

        public const string IS_MANAGE_MODULEField = "@is_manage_module";

        public const string CREATE_USER_IDField = "@create_user_id";

        public const string CREATE_TIMESTAMPField = "@create_timestamp";

        public const string UPDATE_USER_IDField = "@update_user_id";

        public const string UPDATE_TIMESTAMPField = "@update_timestamp";

        public const string ACTIVE_FLAGField = "@active_flag";

        private Int32 _module_id;

        private String _module_name;

        private String _module_descr;

        private Int32 _parent_id;

        private String _module_url;

        private String _div_module_class;

        private String _module_class;

        private Boolean _is_manage_module;

        private Int32 _create_user_id;

        private DateTime _create_timestamp;

        private Int32 _update_user_id;

        private DateTime _update_timestamp;

        private Boolean _active_flag;

        public Int32 module_id
        {
            get { return _module_id; }
            set { _module_id = value; }
        }
        public String module_name
        {
            get { return _module_name; }
            set { _module_name = value; }
        }
        public String module_descr
        {
            get { return _module_descr; }
            set { _module_descr = value; }
        }
        public Int32 parent_id
        {
            get { return _parent_id; }
            set { _parent_id = value; }
        }
        public String module_url
        {
            get { return _module_url; }
            set { _module_url = value; }
        }
        public String div_module_class
        {
            get { return _div_module_class; }
            set { _div_module_class = value; }
        }
        public String module_class
        {
            get { return _module_class; }
            set { _module_class = value; }
        }
        public Boolean is_manage_module
        {
            get { return _is_manage_module; }
            set { _is_manage_module = value; }
        }
        public Int32 create_user_id
        {
            get { return _create_user_id; }
            set { _create_user_id = value; }
        }
        public DateTime create_timestamp
        {
            get { return _create_timestamp; }
            set { _create_timestamp = value; }
        }
        public Int32 update_user_id
        {
            get { return _update_user_id; }
            set { _update_user_id = value; }
        }
        public DateTime update_timestamp
        {
            get { return _update_timestamp; }
            set { _update_timestamp = value; }
        }
        public Boolean active_flag
        {
            get { return _active_flag; }
            set { _active_flag = value; }
        }
        public ModuleData()
        {
            _module_id = 0;
            _module_name = "";
            _module_descr = "";
            _parent_id = 0;
            _module_url = "";
            _div_module_class = "";
            _module_class = "";
            _is_manage_module = false;
            _create_user_id = 0;
            _create_timestamp = DateTime.Now;
            _update_user_id = 0;
            _update_timestamp = DateTime.Now;
            _active_flag = false;
        }
    }

    public class ModuleDataFactory
    {
        public static ModuleData Construct(IDataReader reader)
        {
            ModuleData data = new ModuleData();

            try { data.module_id = Convert.ToInt32(reader["module_id"]); }
            catch { }

            try { data.module_name = Convert.ToString(reader["module_name"]); }
            catch { }

            try { data.module_descr = Convert.ToString(reader["module_descr"]); }
            catch { }

            try { data.parent_id = Convert.ToInt32(reader["parent_id"]); }
            catch { }

            try { data.module_url = Convert.ToString(reader["module_url"]); }
            catch { }

            try { data.div_module_class = Convert.ToString(reader["div_module_class"]); }
            catch { }

            try { data.module_class = Convert.ToString(reader["module_class"]); }
            catch { }

            try { data.is_manage_module = Convert.ToBoolean(reader["is_manage_module"]); }
            catch { }

            try { data.create_user_id = Convert.ToInt32(reader["create_user_id"]); }
            catch { }

            try { data.create_timestamp = Convert.ToDateTime(reader["create_timestamp"]); }
            catch { }

            try { data.update_user_id = Convert.ToInt32(reader["update_user_id"]); }
            catch { }

            try { data.update_timestamp = Convert.ToDateTime(reader["update_timestamp"]); }
            catch { }

            try { data.active_flag = Convert.ToBoolean(reader["active_flag"]); }
            catch { } 

            return data;
        }
        public static Int32 GetPrimaryKey(DataTable dt)
        {
            return GetPrimaryKey(dt, 0);
        }
        public static Int32 GetPrimaryKey(DataTable dt, int rowIndex)
        {
            Int32 PrimaryKey = 0;

            if (dt.Rows.Count < rowIndex + 1)

                return 0;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return 0;

            try { PrimaryKey = Convert.ToInt32(dr[ModuleData.PRIMARYKEY_Field]); }
            catch { }

            return PrimaryKey;
        }
        public static ModuleData Construct(DataTable dt)
        {
            return Construct(dt, 0);
        }
        public static ModuleData Construct(DataTable dt, int rowIndex)
        {
            ModuleData data = new ModuleData();

            if (dt.Rows.Count < rowIndex + 1)

                return null;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return null;

            try { data.module_id = Convert.ToInt32(dr["module_id"]); }
            catch { }

            try { data.module_name = Convert.ToString(dr["module_name"]); }
            catch { }

            try { data.module_descr = Convert.ToString(dr["module_descr"]); }
            catch { }

            try { data.parent_id = Convert.ToInt32(dr["parent_id"]); }
            catch { }

            try { data.module_url = Convert.ToString(dr["module_url"]); }
            catch { }

            try { data.div_module_class = Convert.ToString(dr["div_module_class"]); }
            catch { }

            try { data.module_class = Convert.ToString(dr["module_class"]); }
            catch { }

            try { data.is_manage_module = Convert.ToBoolean(dr["is_manage_module"]); }
            catch { }

            try { data.create_user_id = Convert.ToInt32(dr["create_user_id"]); }
            catch { }

            try { data.create_timestamp = Convert.ToDateTime(dr["create_timestamp"]); }
            catch { }

            try { data.update_user_id = Convert.ToInt32(dr["update_user_id"]); }
            catch { }

            try { data.update_timestamp = Convert.ToDateTime(dr["update_timestamp"]); }
            catch { }

            try { data.active_flag = Convert.ToBoolean(dr["active_flag"]); }
            catch { }

            return data;
        }
        public static ModuleData Construct(DataRow dr)
        {
            ModuleData data = new ModuleData();

            try { data.module_id = Convert.ToInt32(dr["module_id"]); }
            catch { }

            try { data.module_name = Convert.ToString(dr["module_name"]); }
            catch { }

            try { data.module_descr = Convert.ToString(dr["module_descr"]); }
            catch { }

            try { data.parent_id = Convert.ToInt32(dr["parent_id"]); }
            catch { }

            try { data.module_url = Convert.ToString(dr["module_url"]); }
            catch { }

            try { data.div_module_class = Convert.ToString(dr["div_module_class"]); }
            catch { }

            try { data.module_class = Convert.ToString(dr["module_class"]); }
            catch { }

            try { data.is_manage_module = Convert.ToBoolean(dr["is_manage_module"]); }
            catch { }

            try { data.create_user_id = Convert.ToInt32(dr["create_user_id"]); }
            catch { }

            try { data.create_timestamp = Convert.ToDateTime(dr["create_timestamp"]); }
            catch { }

            try { data.update_user_id = Convert.ToInt32(dr["update_user_id"]); }
            catch { }

            try { data.update_timestamp = Convert.ToDateTime(dr["update_timestamp"]); }
            catch { }

            try { data.active_flag = Convert.ToBoolean(dr["active_flag"]); }
            catch { }

            return data;
        }
        public static Int32 GetPrimaryKey(DataRow dr)
        {
            Int32 PrimaryKey = 0;

            try { PrimaryKey = Convert.ToInt32(dr[ModuleData.PRIMARYKEY_Field]); }
            catch { }
            return PrimaryKey;
        }

    }
}